import { Expose } from 'class-transformer';
import { SysUser } from '../../users/entities/user.entity';
import {
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  Index,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Index('uk_code', ['code'], { unique: true })
@Entity('sys_dept', { schema: 'lzo_admin_nestjs' })
export class SysDept {
  @PrimaryGeneratedColumn({ type: 'bigint', name: 'id', comment: '主键111' })
  @Expose()
  id: string;

  @Column('varchar', { name: 'name', comment: '部门名称', length: 100 })
  @Expose()
  name: string;

  @Expose()
  @Column('varchar', {
    name: 'code',
    unique: true,
    comment: '部门编号',
    length: 100,
  })
  code: string;

  @Column('bigint', {
    name: 'parent_id',
    nullable: true,
    comment: '父节点id',
    default: () => "'0'",
  })
  parentId: string | number;

  @Column('varchar', {
    name: 'tree_path',
    comment: '父节点id路径',
    length: 255,
    default: () => "'0'",
  })
  treePath: string;

  @Column('smallint', {
    name: 'sort',
    nullable: true,
    comment: '显示顺序',
    default: () => "'0'",
  })
  sort: number | string;

  @Column('tinyint', {
    name: 'status',
    nullable: true,
    comment: '状态(1-正常 0-禁用)',
    default: () => "'1'",
  })
  status: number | null;

  @Column('bigint', { name: 'create_by', nullable: true, comment: '创建人ID' })
  createBy: string | null;

  @CreateDateColumn({
    name: 'create_time',
    nullable: true,
    comment: '创建时间',
  })
  createTime: Date | null;

  @Column('bigint', { name: 'update_by', nullable: true, comment: '修改人ID' })
  updateBy: string | null;

  @UpdateDateColumn({
    name: 'update_time',
    nullable: true,
    comment: '更新时间',
  })
  updateTime: Date | null;

  @DeleteDateColumn({
    name: 'is_deleted',
    nullable: true,
    comment: '逻辑删除标识(1-已删除 0|false-未删除)',
    default: () => null,
  })
  isDeleted: number | null;

  @Column('datetime', { name: 'deleted_at', nullable: true })
  deletedAt: Date | null;

  @OneToMany(() => SysUser, (sysUser) => sysUser.dept)
  sysUsers: SysUser[];
}
